<template>
  <basic-container>
    <div class="container category-wrap">
      <el-form :model="categoryForm" label-width="150px" label-position="right">
        <el-form-item label="打印机名称" required width="150px">
          <el-input v-model="categoryForm.name" disabled class="form-input"></el-input>
        </el-form-item>
        <el-form-item label="打印机编号" width="150px" required>
          <el-input v-model="categoryForm.machineCode" disabled class="form-input"></el-input>
        </el-form-item>
        <el-form-item label="选择商家" required>
          <el-select v-model="categoryForm.merchantId" disabled placeholder="请选择">
            <el-option
              v-for="item in buyerList"
              :key="item.id"
              :label="item.merchantName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="选择店铺" required>
          <el-select v-model="categoryForm.shopId" disabled placeholder="请选择">
            <el-option
              v-for="item in shopList"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="打印机秘钥" width="150px" required>
          <el-input v-model="categoryForm.secret" disabled class="form-input"></el-input>
        </el-form-item>
        <el-form-item label="启用状态" width="150px" required>
          <el-select v-model="categoryForm.status" disabled placeholder="请选择">
            <el-option
              v-for="item in yes_no"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注信息" width="150px">
          <el-input v-model="categoryForm.remarks" disabled type="textarea" class="form-input"></el-input>
        </el-form-item>
        <div>
          <el-button type="default" size="medium" @click="close">取消</el-button>
        </div>
      </el-form>
    </div>
  </basic-container>
</template>

<script>
  import {
    mapGetters
  } from 'vuex'
  import Request from "../../manage/request.js";
  import {fetchDict} from '@/util/util';
  export default {
    name:'printer',
    data: function(){
      return {
        categoryForm:{
        },
        request: new Request(),
        shopList:[],//店铺列表
        yes_no:[],
        buyerList:[],//商家列表
      }
    },
    computed: {
      ...mapGetters(['tagWel', 'tagList', 'tag', 'website']),
      tagLen() {
        return this.tagList.length || 0
      }
    },
    created(){
      this.getShopList();
      this.getMerchantList();
      fetchDict('scm_yes_no', this.yes_no);
      this.categoryForm = JSON.parse(this.$route.query.res);
      console.log(this.categoryForm.merchantId);
    },
    methods:{
      // 查询 店铺列表
      getShopList() {
        let params = {
          pageSize: 100,
          pageNo: 1,
        };
        this.request.getShopList(params).then(res => {
          if (res.code == 200) {
            this.shopList = res.ext.list;
          }else{
            this.$message.warning("未查询到采购商列表：" + res.msg)
          }
        })
      },
      // 查询商家列表
      getMerchantList() {
        let params = {
          pageSize: 100,
          pageNo: 1,
        };
        this.request.getMerchantList(params).then(res => {
          if (res.code == 200) {
            this.buyerList = res.ext.list;
            this.total = res.ext.count;
          }else{
            this.$message.warning("未查询到采购商列表：" + res.msg)
          }
        })
      },
      close(){
        var str_before = location.href.split('#')[1];
        let { tag, key } = this.findTag(str_before);
        this.$store.commit('DEL_TAG', tag);
        this.$router.go(-1);
      },
      findTag(value) {
        let tag, key
        this.tagList.map((item, index) => {
          if (item.value === value) {
            tag = item
            key = index
          }
        })
        return { tag: tag, key: key }
      }
    }
  }
</script>

<style scoped>
  .el-form-item__content,.form-input{
    width: 300px;
  }
</style>
